package com.huge.simple.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huge.simple.common.request.RequestParameter;
import com.huge.simple.common.response.Result;
import com.huge.simple.system.entity.SysTable;
import com.huge.simple.system.entity.SysTableColumn;
import com.huge.simple.system.service.SysTableColumnService;
import com.huge.simple.system.service.SysTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jihu
 * date 2022-03-28
 */
@Api(tags = "数据库表相关接口")
@RestController
@RequestMapping("/sysTable")
public class SysTableController {

    @Autowired
    private SysTableService sysTableService;

    @Autowired
    private SysTableColumnService sysTableColumnService;


    @PostMapping("/pageList")
    @ApiOperation(value = "获取当前数据库的所有表")
    public Result<IPage<SysTable>> pageList(@RequestBody RequestParameter<SysTable> parameter){
        IPage<SysTable> pageList = sysTableService.pageList(parameter);
        return Result.success(pageList);
    }


    @GetMapping("/getTableColumn")
    @ApiOperation(value = "根据表名获取字段详情")
    public Result<List<SysTableColumn>> getTableColumn(@RequestParam String tableName){
        List<SysTableColumn> sysTableColumns = sysTableColumnService.getTableColumn(tableName);
        return Result.success(sysTableColumns);
    }


}
